package com.naiterui.ehp.bp.security.utils;

import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

@Getter
@AllArgsConstructor
public abstract class BaseJwtUser implements UserDetails, java.io.Serializable {

  protected final Long id;

  protected final String username;

  @JsonIgnore
  protected final String password;

  protected final boolean enabled;

  @JsonIgnore
  protected final Set<GrantedAuthority> authorities;

  @SuppressWarnings("unused")
  public Set<String> getRoles() {
    return this.authorities.stream().map(GrantedAuthority::getAuthority).collect(Collectors.toSet());
  }

  @JsonIgnore
  @Override
  public boolean isAccountNonExpired() {
    return true;
  }

  @JsonIgnore
  @Override
  public boolean isAccountNonLocked() {
    return true;
  }

  @JsonIgnore
  @Override
  public boolean isCredentialsNonExpired() {
    return true;
  }

}
